<template>
  <div class="citys" @click.stop>
    <div class="item">
      <span @click="cityBtn(-1, '')" :class="{ active: -1 === currentIndex }">全城</span>
    </div>
    <div v-if="allCitys" v-for="(city, index) in allCitys" :key="city" class="item">
      <span @click="cityBtn(index, city)" :class="{ active: index === currentIndex }">{{ city }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ViewingCities',
  data() {
    return {
      currentIndex: -1
    }
  },
  props: {
    cinemaList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  methods: {
    cityBtn(index, city) {
      this.currentIndex = index
      this.$emit('cityBtn', city)
    }
  },
  computed: {
    allCitys() {
      return new Set(this.cinemaList.map(city => city.districtName))
    }
  }
}
</script>

<style lang="scss" scoped>
.citys {
  background: #fff;
  position: absolute;
  z-index: 102;
  left: 0;
  top: 0;
  right: 0;
  padding: 0.1rem 0.1rem 0 0.1rem;
  .item {
    float: left;
    width: 25%;
    padding-bottom: 15px;
    padding-right: 10px;
    span {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0.07rem 0.1rem;
      text-align: center;
      color: #797d82;
      border: 0.5px solid #797d821a;
      font-size: 12px;
    }
  }
}
.active {
  color: #ff5f16 !important;
  border: 0.5px solid #ff5f16 !important;
}
</style>